/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MaterialPack;

import javax.microedition.lcdui.Image;
import Supporter.*;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
 *
 * @author Van persie
 */
public class InfoPanel extends MaterialObject {
    
    public static final int ANC_MIDDLE = 1;
    public static final int ANC_LEFT = 0;
    
    private String[] text = null;
    Font myFont = null;
    private boolean isNoBackground = false;
    //private boolean  isTransparentBackground = false;
    //private boolean isAlphaBlend = false;
    private int AnchorMode ;
    
    Image buffer = null;
    
    int red,green,blue;
//    public InfoPanel(String backgPath,String Info, int  x,int y, int wid,int hei,Font font  )
//    {
//        
//        GetGraphicsInfo(x, y, wid, hei);
//        text = Info;
//        if(backgPath != "")
//            LoadImage(backgPath,false,wid,hei);
//        else 
//            isNoBackground = true;
//                
//        myFont = font;
//        isVisible = true;
//        isNoBackground = false;
//        AnchorMode =  ANC_MIDDLE;
//        
//        red = green = blue = 0;
//        //PaintBuffer();
//    }
    public InfoPanel(Image backg,String Info, int  x,int y, int wid,int hei,Font font  )
    {
        
        GetGraphicsInfo(x, y, wid, hei);
        text = new  String[1];
        text[0] = Info;
        if(backg != null)
        {
            
           background = ImageSupporter.scaleImage(backg, wid, hei);
           //if(isTrans)
           //     background = ImageSupporter.transparent(background);
        }
        else 
            isNoBackground = true;
                
        myFont = font;
        isVisible = true;
        isNoBackground = false;
        AnchorMode =  ANC_MIDDLE;
        
        red = green = blue = 0;
        //PaintBuffer();
    }
    
    public void SetColorText(int r, int g, int b)
    {
        red = r;
        green = g;
        blue = b;
    }
    public void deActive()
    {
        
    }
    public void Active()
    {
    }

    public void paint(Graphics g)
    {
        if(IsVisible() == true)
        {
            //g.drawImage(buffer, xPos, yPos,Graphics.TOP | Graphics.LEFT);
            if(background != null)
                g.drawImage(background, getxPos(), getyPos(),Graphics.TOP | Graphics.LEFT);
            g.setFont(myFont);
            int OldCor = g.getColor();
            g.setColor(red, green, blue);
            
            int hei = height/10;
            if(AnchorMode == ANC_LEFT)
                for(int i = 0; i < text.length;i++)
                    g.drawString(text[i], getxPos(), getyPos() + (i+1)*hei + i*10, Graphics.TOP | Graphics.LEFT);
            else
                for(int i = 0; i < text.length;i++)
                    g.drawString(text[i], getxPos() + getWidth()/2 , getyPos() + (i+1)*hei + i*10  , Graphics.HCENTER | Graphics.TOP);

            g.setColor(OldCor);
        }        
    }

    /**
     * @return the isNoBackground
     */
    public boolean isNoBackground() {
        return isNoBackground;
    }

    /**
     * @param isNoBackground the isNoBackground to set
     */
    public void setNoBackground(boolean bit) {
        isNoBackground = bit;
        //PaintBuffer();
    }

    /**
     * @return the AnchorMode
     */
    public int getAnchorMode() {
        return AnchorMode;
    }

    /**
     * @param AnchorMode the AnchorMode to set
     */
    public void setAnchorMode(int AnchorMode) {
        this.AnchorMode = AnchorMode;
    }

    /**
     * @return the text
     */
//    public String text[0] {
//        return text;
//    }

    /**
     * @param text the text to set
     */
    public void setText(String txt) {
        text = new String[1];
        this.text[0] = txt;
        
    }
    public void setText(String [] txt) {
        this.text = txt;
        
    }
}
